package FSMDE.persistence.tests;

import static org.junit.Assert.assertEquals;

import java.util.UUID;

import main.java.FSMDE.models.ComplexComponent;
import main.java.FSMDE.models.Interface;
import main.java.FSMDE.persistence.InterfaceXmlManager;

import org.w3c.dom.Document;

import org.junit.Test;
import org.w3c.dom.Element;

import ERMDE.persistence.tests.TestUtilities;

public class InterfaceXmlManagerTestCase {

	@Test
	public void testCreateInterfaceFromXml() throws Exception {

		String xml = "<interface name='interface1' "
				+ "id='3F2504E0-4F89-11D3-9A0C-0300FFFFFFFF' type='General' graphType='Normal'>"
				+ "<components>"
				+ "<component name='com1' id='3F2504E0-4F89-11D3-9A0C-030AFFFFFFFF' type='Generic' graphType='Normal' genericType='hola'/>"
				+ "<component name='complex' id='3F2504E0-4F89-11D3-9A0C-030DFFFFFFFF' type='Form'>"
				+ "<components>"
				+ "<component name='complex11' id='3F2504E0-4F89-11D3-9A0C-030BFFFFFFFF' type='RadioButton' />"
				+ "<component name='complex22' id='3F2504E0-4F89-11D3-9A0C-030CFFFFFFFF' type='Button' />"
				+ "</components>" + "</component>"
				+ "</components></interface>";

		Document document = TestUtilities.loadXMLFromString(xml);
		Element elem = document.getDocumentElement();
		Interface inface = new InterfaceXmlManager()
				.getItemFromXmlElement(elem);
		assertEquals(inface.getId().toString(),
				"3f2504e0-4f89-11d3-9a0c-0300ffffffff");
		assertEquals(
				inface.getComponents()
						.get(UUID
								.fromString("3f2504e0-4f89-11d3-9a0c-030dffffffff"))
						.getType().toString(), "Form");
		assertEquals(
				inface.getComponents()
						.get(UUID
								.fromString("3f2504e0-4f89-11d3-9a0c-030affffffff"))
						.getGenericType(), "hola");
		assertEquals(((ComplexComponent) inface.getComponents().get("complex"))
				.getComponents().count(), 2);
		assertEquals(((ComplexComponent) inface.getComponents().get("complex"))
				.getComponents().get("complex11").getType().toString(),
				"Radio button");
	}
}
